#include "SIS3801.hh"

const unsigned int SIS3801::SIS3801_USERBIT_MASK         = 0xc0000000;
const unsigned int SIS3801::SIS3801_BANK_NUMBER_MASK     = 0x20000000;
const unsigned int SIS3801::SIS3801_CHANNEL_NUMBER_MASK  = 0x1f000000;
const unsigned int SIS3801::SIS3801_DATA_MASK            = 0x00ffffff;

SIS3801::SIS3801()
{ 

  user_bit       = 0;
  bank_number    = 0;
  channel_number = 0;
  data           = 0;

  return_decoded_data.clear();
  decoded_stream.clear();
};

SIS3801::SIS3801(const char *char_wrd)
{ 
  Decode( char_wrd );
};



SIS3801::~SIS3801() { };


void SIS3801::Decode(const char *char_wrd)
{
  unsigned long int wrd =  strtoul (char_wrd, NULL, 16);

  if(wrd != 0) {
    user_bit       = BitMaskShift(wrd, SIS3801_USERBIT_MASK,        30);
    bank_number    = BitMaskShift(wrd, SIS3801_BANK_NUMBER_MASK,    29);
    channel_number = BitMaskShift(wrd, SIS3801_CHANNEL_NUMBER_MASK, 24);
    data           = BitMaskShift(wrd, SIS3801_DATA_MASK,            0);

    decoded_stream << "----------------------------------------- \n";
    decoded_stream << "       SIS3801    \n";
    decoded_stream << "----------------------------------------- \n";
    decoded_stream << "  Input HEX number : " << char_wrd << "\n";
    decoded_stream << "  User Bit         : " << user_bit       << "\n";
    decoded_stream << "  Bank Number      : " << bank_number    << "\n";
    decoded_stream << "  Channel Number   : " << channel_number << "\n";
    decoded_stream << "  Data             : " << data           << "\n";
    
    data_input_flag = true;
    
  }
  else {
    decoded_stream << "No HEX number is the input Entry" << std::endl;
    data_input_flag = false;
  }
  decoded_stream << std::endl;
  return_decoded_data = decoded_stream.str();
  
  return;
};




